import type {
  Order,
  OrderDeliveryParams,
  OrderMoneyInfoParams,
  OrderPageParams,
  OrderUpdateCloseParams,
  OrderUpdateNoteParams,
  OrderUpdateReceiverInfoParams,
} from '@/models/order'
import type { CommonResult, CommonPage } from '@/models/request'
import request, { ContentTypeEnum } from '@/utils/request'
export function fetchList(params: OrderPageParams) {
  return request<CommonPage<Order>>({
    url: '/order/list',
    method: 'get',
    params: params,
  })
}

export function closeOrder(params: OrderUpdateCloseParams) {
  return request<CommonResult>({
    url: '/order/update/close',
    method: 'post',
    params: params,
    headers: {
      'Content-Type': ContentTypeEnum.form,
    },
  })
}

export function deleteOrder(params: { ids: string }) {
  return request<CommonResult>({
    url: '/order/delete',
    method: 'post',
    params: params,
    headers: {
      'Content-Type': ContentTypeEnum.form,
    },
  })
}

export function deliveryOrder(data: OrderDeliveryParams[]) {
  return request<CommonResult>({
    url: '/order/update/delivery',
    method: 'post',
    data: data,
  })
}

export function getOrderDetail(id: number) {
  return request<CommonResult<Order>>({
    url: '/order/' + id,
    method: 'get',
  })
}

export function updateReceiverInfo(data: OrderUpdateReceiverInfoParams) {
  return request<CommonResult>({
    url: '/order/update/receiverInfo',
    method: 'post',
    data: data,
  })
}

export function updateMoneyInfo(data: OrderMoneyInfoParams) {
  return request<CommonResult>({
    url: '/order/update/moneyInfo',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': ContentTypeEnum.form,
    },
  })
}

export function updateOrderNote(params: OrderUpdateNoteParams) {
  return request<CommonResult>({
    url: '/order/update/note',
    method: 'post',
    params: params,
    headers: {
      'Content-Type': ContentTypeEnum.form,
    },
  })
}
